import { defineStore } from 'pinia'

export const useCartStore = defineStore('cart', {
	state: () => ({
		items: []
	}),
	
	getters: {
		total: (state) => state.items.reduce((sum, item) => sum + item.price, 0),
		count: (state) => state.items.length
	},
	
	actions: {
		addToCart(ticket) {
			this.items.push({
				...ticket,
				cartId: Date.now()
			})
		},
		
		removeFromCart(cartId) {
			const index = this.items.findIndex(item => item.cartId === cartId)
			if (index > -1) {
				this.items.splice(index, 1)
			}
		},
		
		clearCart() {
			this.items = []
		}
	}
}) 